{extend name="common/base"}

{block name="tool_bar"}
<div class="layui-row">
    <div class="layui-col-xs10">
        <form class="layui-form" action="">
            <div class="layui-col-xs5" style="margin-left: 5px; line-height: 38px;">
                <div class="layui-form-item">
                    <input name="search_key" placeholder="请输入昵称/手机号搜索" value="{$search_key}" class="layui-input"
                           type="text">
                </div>
            </div>
            <div class="layui-col-xs4" style="margin-left: 5px; line-height: 38px;">
                <button class="layui-btn layui-btn-primary" lay-submit="" lay-filter="formDemo">
                    <i class="fa fa-search"></i>
                </button>
            </div>
        </form>
    </div>
</div>
{/block}

{block name="body"}
<table class="layui-table" lay-skin="line">
    <colgroup>
        <col width="250">
        <col >
    </colgroup>
    <thead>
    <tr>
        <th>openid</th>
        <th>昵称</th>
        <th>头像</th>
        <th>手机号</th>
        <th>首次访问</th>
        <th>操作</th>
    </tr>
    </thead>
    <tbody>
    {volist name="data" id="vo"}
    <tr>
        <td>{$vo.openid}</td>
        <td>{$vo.nickname}</td>
        <td><img src="{$vo.headimgurl}" alt="{$vo.headimgurl}" style="width: 60px;"></td>
        <td>{$vo.mobile}</td>
        <td>
            {:date('Y-m-d H:i', $vo.create_time)}
        </td>
        <td>
            <a class="bt-a js-refresh" data-id="{$vo.id}">刷新</a>
            <a class="bt-a js-del" data-id="{$vo.id}">删除</a>
        </td>
    </tr>
    {/volist}
    </tbody>
</table>
<div id="page">
    {$page|raw}
</div>
{/block}

{block name="js"}
<script>
    $(function () {
        $('.js-del').on('click', function () {
            var loadingIndex = layer.load(1)
                    ,id = parseInt($(this).data('id'));
            $.post("{:url('delPost')}", {id: id}, function (res) {
                layer.close(loadingIndex);
                if(res.code === 1){
                    layer.msg(res.msg, {time: 1000}, function () {
                        location.reload();
                    });
                }else{
                    layer.alert(res.msg);
                }
            }).error(function (error) {
                layer.close(loadingIndex);
                layer.alert('500 Internal Server Error', {title: '错误提示'});
            });
        });

        $('.js-refresh').on('click', function () {
            var loadingIndex = layer.load(1)
                    ,id = parseInt($(this).data('id'));
            $.post("{:url('refreshPost')}", {id: id}, function (res) {
                layer.close(loadingIndex);
                if(res.code === 1){
                    layer.msg(res.msg, {time: 1000}, function () {
                        location.reload();
                    });
                }else{
                    layer.alert(res.msg);
                }
            }).error(function (error) {
                layer.close(loadingIndex);
                layer.alert('500 Internal Server Error', {title: '错误提示'});
            });
        });
    });
</script>
{/block}